package cn.edu.nwsuaf.examcenter.service.serviceImpl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import cn.edu.nwsuaf.examcenter.pojo.ExamContent;
import cn.edu.nwsuaf.examcenter.service.ExamContentService;
import cn.edu.nwsuaf.examcenter.pojo.ExamItemType;

@Service(value="examContentService")
public class ExamContentServiceImpl extends BaseServiceImpl<ExamContent> implements ExamContentService {

	@Override
	public void examContentPreview(String examPaperNo, ModelMap modelMap) {
		// TODO Auto-generated method stub
		String hql = "FROM ExamContent as examContent where examContent.examPaperInfo.examPaperNo=?";
		String[] param = {examPaperNo};
		
		Map<ExamItemType, List<ExamContent>> map = new LinkedHashMap<>();
		//查询分组
		List<ExamContent> groupList = super.findAll(hql+" group by examContent.examItem.examItemType.examItemTypeNo", param);
		for(ExamContent ec:groupList){
			
			
			ExamItemType examItemType = new ExamItemType();
			examItemType.setExamItemTypeNo(ec.getExamItem().getExamItemType().getExamItemTypeNo());
			examItemType.setExamItemTypeName(ec.getExamItem().getExamItemType().getExamItemTypeName());
			examItemType.setExamItemTypeDescription(ec.getExamItem().getExamItemType().getExamItemTypeDescription());
			
			String hql1 = "FROM ExamContent as examContent where examContent.examPaperInfo.examPaperNo=? and examContent.examItem.examItemType.examItemTypeNo=?";
			String[] param1 = {examPaperNo,ec.getExamItem().getExamItemType().getExamItemTypeNo()};
			
			List<ExamContent> examContentList = super.findAll(hql1, param1);
			map.put(examItemType, examContentList);
			
			
		}
		
		modelMap.addAttribute("examContentMap",map);
	}

}
